// src/main/java/com/example/controller/KettleController.java
package cn.yh.kettle_service.master.controller;


import cn.yh.kettle_service.master.entity.dto.KettleJobRequestDto;
import cn.yh.kettle_service.master.service.KettleJobService;
import cn.yh.kettle_service.utils.Results;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/kettle")
public class KettleController {

    private final KettleJobService jobService;

    public KettleController(KettleJobService jobService) {
        this.jobService = jobService;
    }

    @PostMapping("/start/jobs")
    public Results<String> createJob(@RequestBody KettleJobRequestDto dto) throws Exception {
        return jobService.scheduleJob(dto.getJobName(), dto.getFilePath(), dto.getCron());
    }

    @GetMapping("/get/jobs")
    public Results<List<String>> listJobs() {
        return jobService.listRunningJobs();
    }

    @DeleteMapping("/jobs/{jobName}")
    public Results<String>  deleteJob(@PathVariable String jobName) throws Exception {
        return jobService.deleteJob(jobName);
    }

}
